/**create by liuhua at 2019年5月30日 上午11:28:53**/
package com.star.truffle.module.fzjz.controller.api;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.star.truffle.core.StarServiceException;
import com.star.truffle.core.annotation.IgnoreSecurity;
import com.star.truffle.core.eureka.StarGateway;
import com.star.truffle.core.web.ApiCode;
import com.star.truffle.core.web.ApiResult;
import com.star.truffle.module.fzjz.dto.req.WarInfoRequestDto;
import com.star.truffle.module.fzjz.dto.res.WarInfoResponseDto;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/test")
@Api(tags = "TestApiController")
public class TestApiController {

  @IgnoreSecurity
  @StarGateway
  @RequestMapping(value = "/points", method = RequestMethod.POST)
  @ApiOperation(value = "根据分类获取其点", notes = "根据分类获取其点", httpMethod = "POST", response = WarInfoResponseDto.class)
  public ApiResult<List<WarInfoResponseDto>> points(@Valid @RequestBody WarInfoRequestDto warInfoRequestDto) {
    try {
      List<WarInfoResponseDto> res = Stream.iterate(0, n -> n + 1).limit(66).map(i -> {
        WarInfoResponseDto dto = new WarInfoResponseDto();
        dto.setLng(String.valueOf(Math.random() * 40 + 85));
        dto.setLat(String.valueOf(Math.random() * 30 + 21));
        dto.setIcon("market_cheng.png");
        return dto;
      }).collect(Collectors.toList());
      return ApiResult.success(res);
    } catch (StarServiceException e) {
      return ApiResult.fail(e.getCode(), e.getMsg());
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return ApiResult.fail(ApiCode.SYSTEM_ERROR);
    }
  }

}
